#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QMessageBox>
#include<QUndoStack>
#include<QTextEdit>
#include<QGraphicsRectItem>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->actionredo->setEnabled(false);
    ui->actionundo->setEnabled(false);


   //void canUndoChanged(bool canUndo);
   //void canRedoChanged(bool canRedo);
    QObject::connect(&ui->graphicsView->stack, &QUndoStack::canRedoChanged, [&](bool f) {
        ui->actionredo->setEnabled(f);
    });
    QObject::connect(&ui->graphicsView->stack, &QUndoStack::canUndoChanged, [&](bool f) {
        ui->actionundo->setEnabled(f);
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::on_actionsavestate_triggered()
{
    //stack.push(new MyCommand(ui->textEdit, lastText));
}


void MainWindow::on_append_btn_clicked()
{
    ui->graphicsView->add(ui->spin_pos->value(), ui->spin_val->value());
}


void MainWindow::on_delete_btn_clicked()
{
    ui->graphicsView->del(ui->spin_pos->value(), ui->spin_val->value());
}


void MainWindow::on_actionundo_triggered()
{
    ui->graphicsView->stack.undo();
    ui->graphicsView->paint();
}


void MainWindow::on_actionredo_triggered()
{
    ui->graphicsView->stack.redo();
    ui->graphicsView->paint();
}

